<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Website Search - Admin Page</title>
<style type="text/css">
@charset "utf-8";
/* CSS Document */

body {
	background-color:#d1f2c4;
	margin:0px;
	padding:0px;
	color:#999999;
	font-family:"Trebuchet MS", Arial;
	font-size:14px;
	line-height:1.5em; /* vertical spacing between your lines of text*/
	text-align:center;
}
a, a:link, a:visited {
	color:#7abce5;
}
a:hover {
	color:#c4e9f2;
	text-decoration:none;
}
#wrapper {
	width:960px;
	margin:0px auto 30px auto; /*centers your design on the page*/
	text-align:left;
}
#header {
	height:84px;
	width:960px;
}
#logo {
	width:229px; /*change this width and height to match your logo image*/
	height:46px;
	float:left;
	margin:23px 0 0 23px;
}
#admin_page {
	width:221px; /*change this width and height to match your slogan image*/
	height:45px;
	float:right;
	margin:25px 23px 0 0;
}
#menu_container{
	width:470px;
	height:30px;
	clear:both;
}
#container{
	background-image:url(content_bottom.jpg);
	background-repeat:no-repeat;
	background-position:bottom;
	background-color:#FFF;
	min-height:200px;
	padding-bottom:20px;
}
#container .top{
	width:960px;
	height:5px;
}

#container .content{
	padding:23px;
}


#container .left_column{
	width:470px;
	float:left;
	padding-right:15px;
	border-right:1px solid #dddddd;
}

#container .right_column{
	width:400px;
	float:right;
	
}

input{
	border:1px solid #dddddd;
	background-color:#fafafa;
	padding:4px;
}

textarea{
		border:1px solid #dddddd;
	background-color:#fafafa;
	padding:4px;
}

hr.clear {
	clear:both;
	visibility:hidden;
	margin:0px;
	padding:0px;
}

.preview{
	width:386px;
	border-top:1px dashed #dddddd;
	border-bottom:1px dashed #dddddd;
	padding:10px 0px;
}
</style>
</head>

<body>
<div id="bg_top">
<div id="wrapper">
<div id="header">
<div id="logo"><img src="logo_simple_search.gif" alt="Simple Website Search" /></div>
<div id="admin_page"><img src="admin_page.gif" width="221" height="45" alt="Admin Page" /></div>
</div><!--end header-->
<div id="menu_container"></div><!--end menu-->
<div id="container">
<div class="top"><img src="content_top.jpg" width="960" height="5" alt="_" /></div>
<div class="content">

<?php 

require_once("config.php"); 

if(_SEARCH_DEMO && isset($_REQUEST['trydemo'])){
	?>
	
	<form action="?updateindex=true" method="post">
	Enter your website address to test search: <input type="text" name="demo_url" value="http://"> <br>
	<em>Note: The demo may take a few minutes to load while the first search is performed. The demo search is limited to 20 results. If your website has more than 20 pages it will stop once it reaches 20.</em>
	<br>
	<input type="submit" name="start_demo" value="Start Demo">
	</form>
	<?php
}else if(isset($_REQUEST['updateindex'])){
	chdir("../");
	if(_SEARCH_DEMO && isset($_REQUEST['demo_url']) && preg_match('#^https?://\w+#',$_REQUEST['demo_url'])){
		$_SESSION['_search_demo_url'] = $_REQUEST['demo_url'];
		mail("testing@blueteddy.com.au","PHP Search Demo: ".$_SESSION['_search_demo_url'],var_export($_SERVER,true));
		$GLOBALS['_SEARCH_HTML_WEBSITES'] = array(
			$_SESSION['_search_demo_url']
		);
	}else{
		$_SESSION['_search_demo_url'] = false;
	}
	require_once("search.php");
	?>
	<div id="update_progress">Updating....</div>
	<?php
	$website_search_dynamic->update_index();
	if($_SESSION['_search_demo_url']){
	?>
	<script language="javascript">window.location.href='../search.php';</script>
	<?php }else{ ?>
	<script language="javascript">document.getElementById('update_progress').innerHTML = 'Update complete';</script>
	<?php } ?>
	<a href="?">Click here to continue</a>
	<?php
}else{

	if(isset($_REQUEST['save'])){
		
		
		
		?>
		<h1>Copy the below code:</h1>
		
		<textarea cols="46" rows="20"><?php
		
		echo '$GLOBALS[\'_SEARCH_HTML_WEBSITES\'] = array(' . "\n";
		foreach(explode("\n",$_REQUEST['search_html']) as $line){
			$line = trim($line);
			if(!$line)continue;
			echo "\t\"$line\",\n";
		}
		echo ");\n";
		
		echo '$GLOBALS[\'_SEARCH_HTML_DEPTH\'] = ' . $_REQUEST['search_depth'] . ";\n";
		echo '$GLOBALS[\'_SEARCH_CACHE_LENGTH\'] = ' . $_REQUEST['search_cache'] . ";\n";
		echo '$GLOBALS[\'_SEARCH_ALL_IGNORE\'] = array(' . "\n";
		foreach(explode("\n",$_REQUEST['search_ignore']) as $line){
			$line = trim($line);
			if(!$line)continue;
			echo "\t\"$line\",\n";
		}
		echo ");\n";
		
		?></textarea>
		
		<h1>Paste it over the old "USER CONFIGURATION" code inside config.php</h1>
		<p>ie: Open the phpsearch_files/config.php file in Notepad or your favorite editor (Dreamweaver - Code View) and paste the code.</p>
		<?
		
	}else{
		
		if(!$GLOBALS['_SEARCH_HTML_WEBSITES']){
			$GLOBALS['_SEARCH_HTML_WEBSITES'] = array(
				'http://'.$_SERVER['HTTP_HOST'].str_replace('\\','/',dirname(dirname($_SERVER['REQUEST_URI']))),
			);
		}
	?>
	
	<a href="http://codecanyon.net/user/dtbaker" target="_blank">Click here for help and support</a> <br>
	<?php if(_SEARCH_DEMO){ ?>
	<a href="?trydemo=true">Click here to demo this on your own website</a> <br>
	<?php } ?>
	<a href="?updateindex=true">Click here to update the index</a>
	
	<form action="?save" method="post">
	<h2>Search these website addresses for content:</h2>
	<p>(enter a full website address, 1 per line, like: http://www.google.com)</p>
	<textarea name="search_html" class="" rows="4" cols="90"><?php foreach($GLOBALS['_SEARCH_HTML_WEBSITES'] as $folder) echo $folder."\n"; ?></textarea>
	
	<h2>Search depth:</h2>
	<p>(how far to search within website, increase this number if you find some pages are not included in search results)</p>
	<input name="search_depth" value="<?php echo $GLOBALS['_SEARCH_HTML_DEPTH']; ?>">
	
	<h2>Cache length:</h2>
	<p>(how many days before the cache expires - eg: if you change your website content every 4 days, set this to 4)</p>
	<input name="search_cache" value="<?php echo $GLOBALS['_SEARCH_CACHE_LENGTH']; ?>">
	
	<h2>(advanced) Ignore any files that match these:</h2>
	<p>(enter 1 <strong>regex</strong> per line)</p>
	<p>Example: if you want a file called secret-stuff.html to not appear in search results, add a new line below:  <strong>#secret-stuff\.html#</strong>  (yes, put a \ before any .)</p>
	<textarea name="search_ignore" rows="9" cols="20"><?php foreach($GLOBALS['_SEARCH_ALL_IGNORE'] as $folder) echo $folder."\n"; ?></textarea>
	
	<br>
	<input type="image" src="button_save.gif" border="0" style="border:0;" name="go" value="Generate Config">
	<p>More advanced configuration options are available within config.php</p>
	</form>
	
	<?php } ?>
<?php } ?>
<hr class="clear" />
</div><!--end content-->
<hr class="clear" />
</div><!--end container-->
</div>
</div> <!--end bg_top-->
</body>
</html>
